package com.pkk.components.rpc.page;

import java.io.Serializable;
import lombok.Data;

/**
 * @description: 分页请求类
 * @author: peikunkun
 * @create: 2019-07-04 14:19
 **/
@Data
public class Page implements Serializable {

  private static final long serialVersionUID = -8090519987724339792L;


  /**
   * 页数大小
   */
  private int pageSize = 10;
  /**
   * 第几页
   */
  private int pageIndex = 1;

  /**
   * 排序名称
   */
  private String sortName;

  /**
   * 排序顺序
   */
  private String sortOrder;


  public Page() {
  }

  public Page(int pageIndex, int pageSize) {
    this.pageIndex = pageIndex < 0 ? 0 : pageIndex;
    this.pageSize = pageSize <= 0 ? 20 : pageSize;
  }

  public Page(int pageSize, int pageIndex, String sortName, String sortOrder) {
    this.pageSize = pageSize;
    this.pageIndex = pageIndex;
    this.sortName = sortName;
    this.sortOrder = sortOrder;
  }

  /**
   * 获取当前页
   *
   * @return
   */
  public Integer getCurrentPage() {
    if (pageIndex <= 0) {
      pageIndex = 1;
    }
    return pageIndex;
  }

  /**
   * 获取当前每页显示的条数
   *
   * @return
   */
  public Integer getPageSize() {
    if (pageSize <= 0) {
      pageSize = 10;
    }
    return pageSize;
  }


}
